1036B - Diagonal Walking v2 - CodeForces Solution


math *1600

Please click on ads to support us..

Python Code:

q = int(input())
for i in range(q):
    n,m,k = list(map(int, input().split()))
    if max(n,m) > k:
        print(-1)
    else:
        print(k-int(1 if (n+m) % 2 else (n%2+k%2) % 2 * 2))

C++ Code:

#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f, MOD = 1e9+7;
const int INF_INT = 0x3f3f3f3f;
const long double PI = acosl(-1.), EPS = 1e-9; 
using namespace std;

//cout << fixed << setprecision(6)
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("in", "r", stdin); //test input
    int t;
    cin >> t;
    while(t--){
        ll n, m, k;
        cin >> n >> m >> k;
        ll minmov = max(n,m);

        if(k >= minmov ){
            //so its possible.
            if(n%2 != m%2){
                cout << k-1 << "\n";
            }else{
                if(k%2 == m%2) cout << k << "\n";
                else cout << k-2 << "\n";
            }
        }else cout << "-1\n";
    }
}


Comments

Submit
0 Comments
More Questions

287B - Pipeline
510A - Fox And Snake
1520B - Ordinary Numbers
1624A - Plus One on the Subset
350A - TL
1487A - Arena
1520D - Same Differences
376A - Lever
1305A - Kuroni and the Gifts
1609A - Divide and Multiply
149B - Martian Clock
205A - Little Elephant and Rozdil
1609B - William the Vigilant
978B - File Name
1426B - Symmetric Matrix
732B - Cormen --- The Best Friend Of a Man
1369A - FashionabLee
1474B - Different Divisors
1632B - Roof Construction
388A - Fox and Box Accumulation
451A - Game With Sticks
768A - Oath of the Night's Watch
156C - Cipher
545D - Queue
459B - Pashmak and Flowers
1538A - Stone Game
1454C - Sequence Transformation
165B - Burning Midnight Oil
17A - Noldbach problem
1350A - Orac and Factors